package com.xzl.shop.controller;

import com.xzl.manger.model.Order;
import com.xzl.shop.model.Cart;
import com.xzl.shop.server.CartServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("cart")
public class CartController {
    @Autowired
    private CartServer cartServer;
    @RequestMapping("myCart")
    public ModelAndView myCart(Cart cart){
        List<Cart> list = cartServer.selectCart(cart);
        ModelAndView mv = new ModelAndView();
        mv.addObject("cart",list);
        mv.setViewName("Orders/cart");
        return mv;
    }
    @RequestMapping("submit")
    public ModelAndView submit(String ids){
        Integer userId = cartServer.submit(ids);
        Cart cart = new Cart();
        cart.setUserId(userId);
        return myCart(cart);
    }
    @RequestMapping("delete")
    public ModelAndView delete(String ids){
        Integer userId = cartServer.deleteCarts(ids);
        Cart cart = new Cart();
        cart.setUserId(userId);
        return myCart(cart);
    }
}
